package filmring

class SearchService {

    /**
     * Takes a text query and returns a list of movies with the query as part of their names
     * @param query
     * @return
     */
   public List<Movie> searchMovies(String query){
       List<Movie> searchResults = Movie.executeQuery("SELECT m from Movie as m where LCASE(m.title) like '%${query.toLowerCase()}%'")
       if(searchResults ==null){
           searchResults=[]
       }
       return searchResults
   }

    /**
     * Takes a text query and returns a list of actors with the query as part of their names
     * @param query
     * @return
     */
   public List<Actor> searchActors(String query){
       List<Actor> searchResults = Actor.executeQuery("SELECT a from Actor as a where LCASE(a.name) like '%${query.toLowerCase()}%'")
       if(searchResults ==null){
           searchResults=[]
       }
       return searchResults
   }

   /**
     * Takes a text query and returns a list of directors with the query as part of their names
     * @param query
     * @return
     */
   public List<Director> searchDirectors(String query){
       List<Director> searchResults = Director.executeQuery("SELECT d from Director as d where LCASE(d.name) like '%${query.toLowerCase()}%'")
       if(searchResults ==null){
           searchResults=[]
       }
       return searchResults
   }
}
